package com.my.user.service;

import com.my.user.dao.UserDao;
import com.my.user.dao.UserDaoImpl;
import com.my.user.entity.User;

public class UserServiceImpl implements UserService {

	@Override
	public boolean login(User user) {
		boolean flag=false;
		UserDao uDao=new UserDaoImpl();
		User user1=uDao.selectOne(user.getuName());
		if(user1==null){
			boolean flag1=uDao.login(user);
			if(flag1){
				flag=true;
			}else{
				flag=false;
			}
		}else{
			flag=false;
		}
		return flag;
	}

	@Override
	public User selectOneById(int id) {
		UserDao usDao=new UserDaoImpl();
		User user=usDao.selectOneById(id);
		return user;
	}

	@Override
	public boolean updateOne(User user) {
		UserDao usDao=new UserDaoImpl();
		boolean flag=usDao.updateOne(user);
		return flag;
	}
	
	@Override
	public User landingUser(User user) {
		UserDao usDao=new UserDaoImpl();
		User user2=usDao.selectOne(user.getuName());
		if(user2==null){
			return null;
		}else{
			if(user2.getuPassword().equals(user.getuPassword())){
				return user2;
			}else{
				return null;
			}
		}
		
	}

	@Override
	public boolean selectOneName(User user) {
		boolean flag=false;
		UserDao uDao=new UserDaoImpl();
		User user3=uDao.selectOne(user.getuName());
		if(user3==null){
			flag=true;
		}else{
			flag=false;
		}
		return flag;
	}
}
